<script type="text/javascript" src="j/pagination/jquery.pagination.js"></script>
<script type="text/javascript" src="j/replycontrols.js"></script>
<script type="text/javascript"> 
	
	function undeleteThread(topicId){
			$.get('ajax/forum/mod.php', { type: 'undelete', topic: topicId }, function(data){
				if(data == "ok"){
					//alert("Thread unlocked: "+topicId);
					thisBoard = $('#board_id').attr('title');
					$('#deletetag'+topicId).html(" ");
					$('#deletetag'+topicId).html("<a class='delete_thread' alt='"+topicId+"'>delete</a>");
					$('#topic_box_'+topicId).removeClass();
					$('#topic_box_'+topicId).addClass("forum_topic");
					$('.delete_thread').bind('click', function(){
						topicId = $(this).attr('alt')
						deleteThread(topicId)								 
					});
				} else {
					alert("Thread not undeleted:\n"+data);
				}
			});
	}
	
	function deleteThread(topicId){
			$.get('ajax/forum/mod.php', { type: 'delete', topic: topicId }, function(data){
				if(data == "ok"){
					//alert("Thread unlocked: "+topicId);
					thisBoard = $('#board_id').attr('title');
					$('#deletetag'+topicId).html(" ");
					$('#deletetag'+topicId).html("<a class='undelete_thread' alt='"+topicId+"'>undelete</a>");
					$('#topic_box_'+topicId).removeClass();
					$('#topic_box_'+topicId).addClass("forum_topic_deleted");
					$('.undelete_thread').bind('click', function(){
						topicId = $(this).attr('alt')
						undeleteThread(topicId)								 
					});
				} else {
					alert("Thread not deleted:\n"+data);
				}
			});
	}
	
	function unlockThread(topicId){
			$.get('ajax/forum/mod.php', { type: 'unlock', topic: topicId }, function(data){
				if(data == "ok"){
					$('#lockunlock'+topicId+' a').text('lock');
					$('#lockunlock'+topicId+' a').removeClass();
					$('#lockunlock'+topicId+' a').addClass("lock_thread");
					$('#topic_icon_'+topicId).removeClass();
					$('#topic_icon_'+topicId).addClass("topic_icon");
					$('.lock_thread').bind('click', function(){
						topicId = $(this).attr('alt')
						lockThread(topicId)								 
					});
				} else {
					alert("Thread not unlocked:\n"+data);
				}
			});
	}
	
	function lockThread(topicId){
			$.get('ajax/forum/mod.php', { type: 'lock', topic: topicId }, function(data){
				if(data == "ok"){
					//thisBoard = $('#board_id').attr('title');
					$('#lockunlock'+topicId+' a').text('unlock');
					$('#lockunlock'+topicId+' a').removeClass();
					$('#lockunlock'+topicId+' a').addClass("unlock_thread");
					$('#topic_icon_'+topicId).removeClass();
					$('#topic_icon_'+topicId).addClass("topic_icon_locked");
					$('.unlock_thread').bind('click', function(){
						topicId = $(this).attr('alt')
						unlockThread(topicId)								 
					});
				} else {
					alert("Thread not locked:\n"+data);
				}
			});
	}

	function pageselectCallback(page_index, jq){
			//$('#Searchresult').animate({opacity: 0.0}, 500, 'swing', function(){
				var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone();
				$('#Searchresult').empty().append(new_content);
				$('.forum_topic_link').unbind();
				$('.forum_topic_link').bind('click', function(){
					var Anchor = $(this).attr("href");
					if(Anchor.match(':')){
						args = Anchor.split(':')[1]
						Anchor = Anchor.split(':')[0]
					} else {
						args = null;  
					}
					fetchPage('topic', args);
			
				}); 
				bindControls();
			//})
			//$('#Searchresult').animate({opacity: 1.0}, 500)
		return false;
	}
   
	function initPagination() {
		var num_entries = $('#hiddenresult div.result').length;
		// Create pagination element
		$("#Pagination").pagination(num_entries, {
			num_edge_entries: 2,
			num_display_entries: 8,
			callback: pageselectCallback,
			items_per_page:1
		});
	 }
	 
	 function bindControls(){
		 
			$('.forum_topic_link_empty').bind('click', function(){
					$('.new_topic_box').trigger('click');	
			});
			$('.lock_thread').bind('click', function(){
				topicId = $(this).attr('alt');
				lockThread(topicId);
			});
			
			$('.unlock_thread').bind('click', function(){
				topicId = $(this).attr('alt')
				unlockThread(topicId);
			});
		
			$('.delete_thread').bind('click', function(){
				topicId = $(this).attr('alt')
				deleteThread(topicId);
			});
		
			$('.undelete_thread').bind('click', function(){
				topicId = $(this).attr('alt')
				undeleteThread(topicId);
			});
		
			//hover states on the static widgets
			$('.new_topic_box').hover(
				function() { $(this).addClass('ui-state-hover'); }, 
				function() { $(this).removeClass('ui-state-hover'); }
			)
			
			if($('#hide_status').attr('tt')=="hidden"){
				$('.forum_topic_deleted').slideUp(200);
			}
			
			$('#hide_del').bind('click', function(){
				if($('#hide_del:checked').length==1){
					checked = "hidden"
					$.get('ajax/forum/sethidden.php', { set: 'hide' }, function(data){
						if(data=="ok"){
							fetchPage("board", "{{board_id}}");
							$('#hide_status').attr('tt', 'hidden');
							$('.forum_topic_deleted').slideUp(200);
						} else {
							alert(data);	
						}
					});
				} else {
					checked = "unhidden"
					$.get('ajax/forum/sethidden.php', { set: 'unhide' }, function(data){
						if(data=="ok"){
							fetchPage("board", "{{board_id}}");
							$('#hide_status').attr('tt', 'unhidden');
							$('.forum_topic_deleted').slideDown(200);
						} else {
							alert(data);	
						}
					});
				}									 
			});
			
			bindReplyControls();
		 
	 }
			
	$(document).ready(function(){   
		
		$("#new-loading").hide();
		initPagination();
		
		$('.breadlink').bind('click', function(){
		  var Anchor = $(this).attr("href");
		  if(Anchor.match('#')){
			  if(Anchor.match(':')){
				  args = Anchor.split(':')[1]
				  Anchor = Anchor.split(':')[0]
			  } else {
				  args = null;  
			  }
			  switch(Anchor){
				  case '#forum':
					fetchPage('forum', args)
				  break;
				  case '#board':
					fetchPage('board', args)
				  break;
				  case '#topic':
					fetchPage('topic', args)
				  break;
			  }
		  }
		})
		
		bindControls();		

		//reassert(".forum_topic_link");
		//reassert(".forum_topic_link_deleted");
		
	});
	
</script>
<div id="reply_box_container"></div>
<input name="reply_box_active" id="reply_box_active" type="hidden" value="0" />
<input name="reply_topic" id="reply_topic" type="hidden" value="" />
<input name="reply_category" id="reply_category" type="hidden" value="{{category_id}}" />
<input name="reply_board" id="reply_board" type="hidden" value="{{board_id}}" />
<input name="reply_title" id="reply_title" type="hidden" value="" />
	<div id="breadbasket">
        <div class="breadcrumbs"><a class="breadlink home_icon" href="#forum">Forums</a> > <a class="breadlink" id="no_highlight" href="{{category_link}}">{{category_text}}</a> > <a class="breadlink" id="no_highlight" href="{{board_link}}">{{board_text}}</a></div>
	</div>
    <div class="thread_control"><div class="new_topic_box ui-state-default ui-corner-all">start new topic</div><div id="hide_deleted{{h_del}}"><div id="login-side-loading" class="loading-small"></div><label><input {{checked}} id="hide_del" type="checkbox" /> hide deleted</label><div id="hide_status" tt="{{hide_status}}"></div></div></div>
    <div id="Pagination" class="pagination"></div>
    
        <div style="clear:both;"></div>
    <div class="categorybox">
        <div class="forum_topic_header ui-corner-top">
            <div class="topic_icon_null"></div>
            <div class="topic_details">
                <div class="topic_name"><div class="cat_name">{{board_name}}</div></div>            
            </div>
            <div class="topic_replies">Replies</div>
            <div class="topic_views">Views</div>
            <div class="topic_last_post">Last post</div>
        </div>
        <div style="clear:both"></div>
        <div style="clear:both;"></div>
        <div id="Searchresult">
        </div>
        <div id="hiddenresult" style="display:none;">
            {{board_html}}
        </div>
        <div style="clear:both;"></div>
        <div class="clear"></div>
	</div>            
        